<template>
  <div class="review-team">
    <el-table :data="tableData" stripe style="width: 100%" max-height="600">
      <el-table-column prop="expertsInfo" label="用户">
        <template slot-scope="scope">
          <el-badge
            value="组长"
            class="item"
            type="warning"
            v-if="scope.row.leader != 'NO'"
          >
            {{ scope.row.expertsInfo | showUserInfo }}
          </el-badge>
          <span v-else>
            {{ scope.row.expertsInfo | showUserInfo }}
          </span>
        </template>
      </el-table-column>
      <el-table-column prop="name" label="备注">
        <template slot-scope="scope">
          {{ scope.row.name || '--' }}
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="创建时间" width="180">
      </el-table-column>
      <el-table-column label="操作" width="180">
        <template slot-scope="{ row }">
          <el-button-group>
            <el-button
              type="primary"
              size="mini"
              :disabled="row.leader != 'NO'"
              @click="handleLeader(row)"
            >
              设为组长
            </el-button>
            <el-button type="danger" size="mini" @click="handleDelete(row)">
              删除
            </el-button>
          </el-button-group>
        </template>
      </el-table-column>
      <div slot="empty" class="emptyBg">
        <el-empty :image-size="200"></el-empty>
      </div>
    </el-table>
    <Pagination
      v-show="parseInt(pageObj.count) > 0"
      :total="parseInt(pageObj.count)"
      @change="getList"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
    />
  </div>
</template>
<script>
import {
  expertsReviewTeamQuery,
  expertsReviewTeamDelete,
  expertsReviewTeamSetLeader,
} from '@/api/admin/audit/expertsReviewTeam.js'
import Bus from '@/utils/bus.js'
export default {
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 10,
        reviewId: '',
      },
      tableData: [],
      pageObj: {},
      initialValue: {
        userId: [],
      },
    }
  },
  props: ['reviewData'],
  watch: {
    reviewData: {
      immediate: true,
      handler() {
        this.listQuery.reviewId = this.reviewData.id
      },
    },
  },
  mounted() {
    this.getList()
    Bus.$on('refreshReviewTeam', (v) => {
      if (v) {
        Object.assign(this.listQuery, v)
      }
      this.getList()
    })
  },
  beforeDestroy() {
    Bus.$off('refreshReviewTeam')
  },
  methods: {
    getList() {
      expertsReviewTeamQuery(this.listQuery).then((res) => {
        this.tableData = res.data.data
        this.pageObj = res.data
      })
    },
    //设为组长
    handleLeader({ id, reviewId }) {
      expertsReviewTeamSetLeader({ id, reviewId }).then((res) => {
        this.getList()
      })
    },
    //删除确认
    handleDelete(row) {
      this.$confirm('确定要删除吗?', '提示', {
        confirmButtonText: '删除',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.delete(row)
        })
        .catch(() => {})
    },
    //删除
    delete(row) {
      expertsReviewTeamDelete(row.id).then((res) => {
        this.getList()
        this.$message({
          message: '操作成功',
          type: 'success',
        })
      })
    },
  },
}
</script>
<style scoped>
.review-team >>> .el-table .cell {
  overflow: inherit;
}
</style>